package com.beiding.hotcode;

public interface MyClass {

    Class getType();

    Object invokeCatch(String method, Object... params) throws Throwable;

    default Object invoke(String method, Object... params) {
        try {
            return invokeCatch(method, params);
        } catch (Throwable e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            }
            RuntimeException runtimeException = new RuntimeException(e.getMessage(), e.getCause());
            runtimeException.setStackTrace(e.getStackTrace());
            throw runtimeException;
        }
    }


    void set(String field, Object value);

    Object get(String field);

    default <T> T get(String field, Class<T> type) {
        return (T) get(field);
    }

    MyInstance newInstance(Object... params);

    <T> MyMethod<T> method(String name, Class<T> type);

    default MyMethod method(String name) {
        return method(name, Object.class);
    }

}
